package com.ls.lsbase.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**MD5摘要
 * Created by admin on 2017/5/19.
 */

public class Md5Utils {
    public static String get32md5(String message) {
        MessageDigest messageDigest = null;
        StringBuffer md5StrBuff = new StringBuffer();
        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            messageDigest.update(message.getBytes("UTF-8"));

            byte[] byteArray = messageDigest.digest();
            for (int i = 0; i < byteArray.length; i++) {
                if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
                    md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
                else
                    md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
            }
        } catch (Exception e) {
            throw new RuntimeException();
        }
        return md5StrBuff.toString();//字母小写
    }
    public static String get32MD5(String message) {
        return get32md5(message).toUpperCase();//字母大写
    }
    public static String get16md5(String strInto) {
        return get32md5(strInto).substring(8, 24);
    }
    public static String get16MD5(String strInto) {
        return get16md5(strInto).toUpperCase();
    }
}
